﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using BLL;
namespace Business
{
    /// <summary>
    /// 登录 注册 注销
    /// </summary>
    public class StateMange
    {
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="Email"></param>
        /// <param name="Psw"></param>
        /// <returns></returns>
        public static int Login(String Email, String Psw)
        {
            BLL_user us = new BLL_user();
            _user _us = new _user();
            _us._user_email = Email;
            _us = us.search(_us);
            if (_us == null)
            {
                return -1;   //用户名不存在
            }
            else
            {
                if (_us._user_psw.Trim().Equals(Psw))
                {
                    return 1; //登录成功
                }
                else
                    return 0; //密码错误
            }
        }

        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="Email"></param>
        /// <param name="Psw"></param>
        /// <returns></returns>
        public static bool Register(String Email, String Psw)
        {
            BLL_user bll_us = new BLL_user();
            _user us = new _user();
            us._user_email = Email;
            if (bll_us.search(us) == null)
            {
                us._user_email = Email;
                us._user_psw = Psw;
                if (bll_us.insert(us))
                {
                    BLL_userinfo bll_ui = new BLL_userinfo();
                    _userinfo _ui = new _userinfo();
                    _ui._user_email = Email;
                    _ui._user_name = DefaultDB.DF_USERNAME;
                    _ui._user_image = DefaultDB.DF_USERIMAGE;
                    if (!bll_ui.insert(_ui))
                    {
                        bll_us.delete(us);
                        return false;
                    }
                    return true;
                }
            }
            return false;
        }

        public void LogOff()
        {

        }
    }
}
